package org.cwgl.actions;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.cwgl.interfaces.BaseDataService;
import org.cwgl.util.Json;
import org.cwgl.vo.ClimasVo;
import org.cwgl.vo.Result;

public class ClimasAction {

	//前台封装的财务对象
	public ClimasVo climas=new ClimasVo();
	
	//基础数据业务类
	public BaseDataService service;
	
	
	public BaseDataService getService() {
		return service;
	}

	public void setService(BaseDataService service) {
		this.service = service;
	}

	public ClimasVo getClimas() {
		return climas;
	}

	public void setClimas(ClimasVo climas) {
		this.climas = climas;
	}

	/**
	 * 增加财务对象
	 * @return
	 */
	public String addClimas()
	{
		
		Result result = new Result();
		result.setSuccess(false);
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out = null;
		try 
		{
			out = response.getWriter();
			result.setSuccess(true);
		} catch (IOException e) 
		{
			result.setException(e.getMessage());
		} finally 
		{
			if (result.getSuccess() == true) {
				result = service.addClamis(this.climas);
			}
			out.print(Json.JSON_Object(result));
			out.flush();
		}
		return (null);
	}
	
	/**
	 * 更新财务对象
	 * @return
	 */
	public String updateClimas()
	{
		Result result = new Result();
		result.setSuccess(false);
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out = null;
		try 
		{
			out = response.getWriter();
			result.setSuccess(true);
		} catch (IOException e) 
		{
			result.setException(e.getMessage());
		} finally 
		{
			if (result.getSuccess() == true) {
				result = service.updateClimas(this.climas);
			}
			out.print(Json.JSON_Object(result));
			out.flush();
		}
		return (null);
	}
	
	/**
	 * 删除财务对象
	 * @return
	 */
	public String delClimas()
	{
		Result result = new Result();
		result.setSuccess(false);
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out = null;
		try 
		{
			out = response.getWriter();
			result.setSuccess(true);
		} catch (IOException e) 
		{
			result.setException(e.getMessage());
		} finally 
		{
			if (result.getSuccess() == true) {
				result = service.deleteClamis(this.climas);
			}
			out.print(Json.JSON_Object(result));
			out.flush();
		}
		return (null);
	}
}
